﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iSun.Model;
using iSun.Entity;
using iSun.BLL.Base;
using iSun.Common;

using System.Data.SqlClient;
using System.Data;
namespace iSun.BLL
{
    public partial class BPhoto : BLL.Base.BaseBussnies
    {
        
        /// <summary>
        /// 构造函数
        /// </summary>
        public BPhoto()
        {
            this.entity = new Photo();
        }
         
        public bool SavePhoto()
        {
            base.Insert();
            Photo photo = this.entity as Photo;
            string sql = "Insert into PhotoImage (Oid,PhotoID,PhotoImage) values (@Oid,@PhotoID,@PhotoImage)";
            SqlParameter[] parameters = new SqlParameter[3];
            parameters[0] = new SqlParameter("@Oid", SqlDbType.UniqueIdentifier);
            parameters[0].Value = photo.iSun_ImageEntity.Oid;
            parameters[1] = new SqlParameter("@PhotoID", SqlDbType.UniqueIdentifier);
            parameters[1].Value = photo.iSun_ImageEntity.PhotoID;
            parameters[2] = new SqlParameter("@PhotoImage", SqlDbType.Image);
            parameters[2].Value = photo.iSun_ImageEntity.PhotImage;
            int i= this.RunSqlCommand(sql,parameters);
            return i==0;
        }

        public bool IsExists(string folder,string filename)
        {
            this.entity = new Photo();
            IList<Photo> list = this.GetEntitysByCondition<Photo>(string.Format("PhotoDir='{0}' and PhotoFileName='{1}'", folder, filename));
            return list != null && list.Count > 0;
        }

        public bool SendToCommon(string dir,string filename)
        {
            return false;
        }

        //public override bool Insert()
        //{
        //    return SavePhoto();
        //   //return base.Insert();
        //}

        public BPhoto(Photo photo)
        {
            this.entity = photo;
        }
    }
}
